package com.taotao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.mapper.TbContentMapper;
import com.taotao.mapper.TbContentqueryListMapper;
import com.taotao.pojo.TbContent;
import com.taotao.service.QueryListContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QueryListContentServiceImpl implements QueryListContentService {

    @Autowired
    private TbContentqueryListMapper tbContentqueryListMapper;

    @Override
    public EasyUIDataGridResult queryListByCategoryId(Long categoryId, Integer page, Integer rows)throws Exception {
        if (page == null) page = 1;
        if (rows == null) rows =30;
        PageHelper.startPage(page,rows);
        List<TbContent> list = tbContentqueryListMapper.queryContentList(categoryId);
        EasyUIDataGridResult result = new EasyUIDataGridResult();
        PageInfo<TbContent> pageInfo = new PageInfo<TbContent>(list);
        result.setTotal((int)pageInfo.getTotal());
        result.setRows(pageInfo.getList());
        return result;
    }
}
